$(document).ready(function(){
						   
	$.nyroModalSettings({zIndex: 10000}, 'css', 'bg');
	$.nyroModalSettings({zIndex: 10010}, 'css', 'wrapper');

	
	MajHeader();
	
	$(".LoginField").val('login').css('color', '#333');
	
	$(".LoginField").focus(function(){
		$(this).val('').css('color', '#000');
	});
	
	$(".PasswordField").val('password').css('color', '#333');
	
	$(".PasswordField").focus(function(){
		$(this).val('').css('color', '#000');
	});
	
	

	$("li.Header_BtnSousListe").hover(function(){
		$(this).find("ul.sousMenu").slideDown('fast');
	},function(){
		$(this).find("ul.sousMenu").slideUp('fast');
	});
	
	$(".SubMenu").hover(function(){
		$(this).addClass("On");
	},function(){
		$(this).removeClass("On");
	});
	
	
	
	$(".FrBtn").click(function(){
		document.location.href = './index.php?lang=Fra';		
	});
	
	$(".BtnGroupe").click(function(){
		document.location.href = './groupe.php';		
	});
	
	
	$(".EnBtn").click(function(){
		document.location.href = './index.php?lang=Eng';		
	});
	
	
	$(".PhotoContenerAction").hover(function(){
		$(this).html('<span style="background-image:url(' + $(this).attr('urlImg') + '); display:block; background-color:#000;background-position:center center; background-repeat:no-repeat; height:280px; width:280px;text-align:center;position:relative; margin:-275px 0 0 -275px; padding:3px; border:1px solid #FFF;"></span>');
		//$(this).find('span').attr('style', 'background-image:url(' + $(this).attr('urlImg') + ')');
	},function(){
		$(this).html('');
		//$(this).find('span').attr('style', 'background-image:none');
	});
	
	
	
	if($("#Global.ErreurLog").length){
		
		
		if($('body').hasClass('Eng')) msgErr = 'Login error, please retry';
		else msgErr = 'Erreur d\'identification, merci d\'essayer à nouveau';
			
		$.nyroModalManual({
				  content: msgErr,
				  width: 200,
				height:100
				});
			
	}
		
	if($(".tRechercheDirectNum").length){
			$(".tRechercheDirectNum").click(function(){
				$("#tRechercheDirectNum_Direct").val($(this).attr('tRechercheDirectNum'));	  
				$("#Form_Search_Direct").submit();
			});
	}

	
	if($(".tRechercheSalon").length){
			$(".tRechercheSalon").click(function(){
				$("#tSalonNum_Direct").val($(this).attr('Salon'));	  
				$("#Form_Search_Direct").submit();
			});
	}

	
	if($(".DirectSearch.SpecialARCHI").length){
			$(".DirectSearch.SpecialARCHI").click(function(){
				$("#uPrescripteur_Direct").val('1');	  
				$("#Form_Search_Direct").submit();
			});
	}
	
	if($(".DirectSearch.ParcoursMusees").length){
			$(".DirectSearch.ParcoursMusees").click(function(){
				$("#uMusees_Direct").val('1');	  
				$("#Form_Search_Direct").submit();
			});
	}
	
	
	if($("#Recherche").length){

		//chargement des produit par default
		if($(".RechercheTypeProduit").length){
			$.ajax({
					url: "./layouts/ajax/Produits.php",
					type: "POST",
					success: function(feedback){
									$('.RechercheTypeProduit').html(feedback);
							 }
			});
		}
		
		//chargement des secteurs au changement du select Salon
		if($("#tSalonNum").length){
			
			$("#tSalonNum").change(function () {	

				var SalonNum = $(this).val();
				
				$.ajax({
						url: "./layouts/ajax/Secteurs.php",
						type: "POST",
						data: {tSalonNum:SalonNum},
						success: function(feedback){
										$('.SecteurLi').remove();
										if(SalonNum!='') $('.RechercheSalon').after(feedback);
								 }
				});
				
				$.ajax({
						url: "./layouts/ajax/Produits.php",
						type: "POST",
						data: {tSalonNum:SalonNum},
						success: function(feedback){
							$('.RechercheTypeProduit').html(feedback);
						}
				});
				
			});
		}
		
		//Gestion du retour modification Recherche
		if($("#tSalonNum").val()!=""){
			
			var SalonNum = $("#tSalonNum").val();
			
			$.ajax({
					url: "./layouts/ajax/Secteurs.php",
					type: "POST",
					data: {tSalonNum:SalonNum},
					success: function(feedback){
									$('.SecteurLi').remove();
									if(SalonNum!='') $('.RechercheSalon').after(feedback);
							 }
			});
			
			$.ajax({
					url: "./layouts/ajax/Produits.php",
					type: "POST",
					data: {tSalonNum:SalonNum},
					success: function(feedback){
						$('.RechercheTypeProduit').html(feedback);
					}
			});
			
		}
		
	
	}
	
	
	if($("#BtnRecherche").length){
		$("#BtnRecherche").click(function(){
				$("#Form_Search").submit();						   
		});
	}
	
	if($(".PictoWeb.On").length){
		$(".PictoWeb.On").click(function(){
				window.open('http://' + $(this).attr('LinkWeb'), '', 'menubar=yes, status=yes, scrollbars=yes, menubar=yes, width=800, height=600, resizable=yes');
		});
	}
	
	
	if($(".PictoPlan.On").length){
		$(".PictoPlan.On").click(function(){
				document.location.href='eplanView.php?id_hall='+$(this).attr('Hall')+'&enlight='+$(this).attr('Stand');
		});
	}
	
	if($(".LiTri").length){
		$(".LiTri").click(function(){
				document.location.href=$(this).attr('action') + '.php?sort='+$(this).attr('sort');
		});
	}
	
	
	
	if($(".NomDeStand .LeCommentaire").length){
		$(".NomDeStand .LeCommentaire").click(function(){
				 $.nyroModalManual({
									  url: './layouts/ajax/AddPrior.php?Action=Get&aNumeroInsertion=' + $(this).attr('aNumeroInsertion'),
									  width: 465,
										height:320
									});
		});
	}
	
	
	if($(".NomDeStand .LeNom").length){
		$(".NomDeStand .LeNom").click(function(){
				 $.nyroModalManual({
									  	url: './layouts/ajax/InsertionView.php?aNumeroInsertion=' + $(this).attr('aNumeroInsertion'),
									  	endShowContent: CallBackInsertionNyro,
									  	width: 605,
										height:620
									});
		});
	}
	
	
	GenereAllToolTip();
	
	
	if($(".BtnNewSearch").length){
		$(".BtnNewSearch").click(function(){
			document.location.href = 'index.php';
		});
	}
	
	if($(".AjaxImpirm").length){
		$(".AjaxImpirm").click(function () {	
			 
			 if($('body').hasClass('Eng')) {
				 msgErr1 = "Warning, this action cannot be undone! - Have you finished selecting the exhibitors that interest you?";
				 msgErr2 = "The PDF can only be generated once; you will no longer be able to modify your exhibitor selection on your e-Plan or regenerate your PDF file";
			 } else {
				 msgErr1 = "Attention action irreversible ! - Avez-vous terminé de sélectionner les exposants qui vous intéressent ?";
				 msgErr2 = "Le pdf ne peut-être généré qu'une seule fois, vous ne pourrez donc plus modifier votre sélection d'exposants dans votre e-Plan, ni regénérer votre pdf";
			}
			 
			 
			 if (confirm(msgErr1)){
				
				if (confirm(msgErr2)){
					
					document.location.href='eplanView.php?direct_print=1';
					
				}
				 
			 }
		});
	}
	
	if($(".AjaxImpirmOff").length){
		$(".AjaxImpirmOff").click(function () {	
			if($('body').hasClass('Eng')) alert('You have already printed your e-Plan');
			else alert('Vous avez deja imprime votre e-Plan');
			
		});
	}
	
	if($(".MotPassPerdu").length){
		$(".MotPassPerdu").click(function () {	
			if($('body').hasClass('Eng')) Lang = 'EN';
			else Lang = 'FR';
			
			window.open('http://www.expandsolutions.fr/mo/CompteOubliPassword.aspx?Language=' + Lang, '', 'menubar=yes, status=yes, scrollbars=yes, menubar=yes, width=800, height=600, resizable=yes');
		});
	}
	
	if($(".ObtenirPass").length){
		$(".ObtenirPass").click(function () {	
			if($('body').hasClass('Eng')) Lang = 'en';
			else Lang = 'fr';
			
			window.open('http://www.maison-objet.com/'+Lang+'/index.php?page=espace-visiteur', '', 'menubar=yes, status=yes, scrollbars=yes, menubar=yes, width=800, height=600, resizable=yes');
		});
	}
	
	
	
	

	if($(".BtnModSearch").length){
		$(".BtnModSearch").click(function(){
			document.location.href = 'index.php?SearchMod=1';
		});
	}
	
	
	$(".Hall1.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=1';
	});
	$(".Hall2.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=2';
	});
	$(".Hall3.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=3';
	});
	$(".Hall4.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=4';
	});
	$(".Hall5A.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=5A';
	});
	$(".Hall5B.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=5B';
	});
	$(".Hall5C.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=5C';
	});
	$(".Hall6.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=6';
	});
	$(".Hall7.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=7';
	});
	$(".Hall8.Click").click(function(){
			document.location.href = 'eplanView.php?id_hall=8';
	});
	
	
	
	$(".Demo").click(function(){
			document.location.href = 'demo.php';
	});
	
	
	$(".Expand").click(function(){
			//alert('lien vers chez Expand');
	});
	
	
	
	
	
	if($(".AddPrior").length){
		AddPrior();
	}
	
	if($(".BtnAddSearchFav").length){
		$(".BtnAddSearchFav").click(function () {	
			$.ajax({
					url: "./layouts/ajax/SearchFav.php",
					type: "POST",
					data: {Add:'Oui'},
					success: function(feedback){
						
									 $.nyroModalManual({
												  url: './layouts/ajax/SearchFav.php?Get=' + feedback,
												  width: 465,
													height:220
												});

							 }
			});
		});
	}
	
	if($(".BtnDelFavSearch").length){
		$(".BtnDelFavSearch").click(function () {
			
			elt = $(this);
			
			if($('body').hasClass('Eng')) alertMsg = 'Are you sure you want to delete this favorite search ?';
			else alertMsg = 'Êtes vous sur de vouloir supprimer cette recherche favorite ?';
			
			if (confirm(alertMsg)) {
				$.ajax({
						url: "./layouts/ajax/SearchFav.php",
						type: "POST",
						data: {Del:'Oui',IdDel:$(this).attr('id')},
						success: function(feedback){
									elt.parent().parent().parent().slideUp("slow");
								 }
				});
			}
			
		});
	}
	
	if($(".BtnEditFavSearch").length){
		$(".BtnEditFavSearch").click(function () {	
				 $.nyroModalManual({
							  url: './layouts/ajax/SearchFav.php?Get=' + $(this).attr('id'),
							  width: 465,
								height:220
							});
		});
	}
	
	
	if($(".FavTitrePerso").length){
		$(".FavTitrePerso").click(function () {	
			$(this).find('form').submit();
		});
	}
	
						   
});


function AddPrior(){
		
		$(".AddPrior").unbind('click', '');
		
		$(".AddPrior").click(function () {	
									   
			NumInsert = $(this).attr('aNumeroInsertion');
			level =  $(this).attr('level');
			elt = $(this);	
			
			$.ajax({
					url: "./layouts/ajax/AddPrior.php",
					type: "POST",
					data: {aNumeroInsertion:NumInsert ,Level:level, Action:'Add'},
					success: function(feedback){
								
								testOn = elt.parent().find('li.On');
								testOnLevel = testOn.attr('level');
								
								if(!elt.hasClass('On')) {
									
									if(testOnLevel){
										//l insertion est dans la panier - changement de level
										//deselectionner l ancienne
										$('li#LiResult_' + NumInsert + ' li.AddPrior').removeClass('On').addClass('Off');
										$('li#LiResult_' + NumInsert + ' li.AddPrior a').removeClass('On').addClass('Off');
										
										if(elt.parent().find('li').hasClass('InsertView')){
											elt.parent().find('li').removeClass('On').addClass('Off');
											elt.parent().find('li a').removeClass('On').addClass('Off');
										}

										
									} else {
										//l insertion n etait pas dans le panier
										//ajout du div commentaire
										if(!$('li#LiResult_' + NumInsert).find('.LeCommentaire').length){
											$('li#LiResult_' + NumInsert).find('.LeNom').before('<div class="LeCommentaire CursorPointer" aNumeroInsertion="' + NumInsert + '"></div>');	
											
											
											$('li#LiResult_' + NumInsert).find(".LeCommentaire").click(function(){
													 $.nyroModalManual({
														  url: './layouts/ajax/AddPrior.php?Action=Get&aNumeroInsertion=' + $(this).attr('aNumeroInsertion'),
														  width: 465,
															height:320
														});
											});
											
										}
									}
									
									//selectionner la nouvelle
									elt.removeClass('Off').addClass('On');
									elt.find('a').removeClass('Off').addClass('On');
									
									if(elt.parent().find('li').hasClass('InsertView')){
										$('li#LiResult_' + NumInsert + ' li.Prior' + level).removeClass('Off').addClass('On');
										$('li#LiResult_' + NumInsert + ' li.Prior' + level + ' a').removeClass('Off').addClass('On');
									}
									
								} else {
									
									//suppression de la ligne
									if(elt.hasClass('EplanPrior') || elt.parent().find('li').hasClass('InsertView') ) $('li#LiResult_' + NumInsert).slideUp("slow");
									else {
										elt.removeClass('On').addClass('Off');
										elt.find('a').removeClass('On').addClass('Off');
										if($('li#LiResult_' + NumInsert).find('.LeCommentaire').length)	$('li#LiResult_' + NumInsert).find('.LeCommentaire').remove();
									}
									
								}
								
								AddPrior();
								GenereAllToolTip();
																
								MajHeader();
								
							 }
			});
		});

}


function AddToolTip(EltByClass, contenu){	

		EltByClass.qtip({
		   content: contenu,
		   show: 'mouseover',
		   hide: 'mouseout',
		   
		   position: {
			  corner: {
				 target: 'bottomMiddle',
				 tooltip: 'topLeft'
			  }
		   },
		   
		   style: { 
			 padding: 5,
			 textAlign: 'center',
			 tip: 'topLeft',
			 color:'#000',
			 name: 'cream',
			 border: {
				 width: 7,
				 radius: 5
			  }
		   }
		})
		
	}
	
function GenereAllToolTip(){
		
		DestroyAllToolTip();
		
		if($('body').hasClass('Eng')){ 
			
			if($(".PictoWeb.On").length) AddToolTip( $(".PictoWeb.On"), 'View the website');
			if($(".PictoPlan.On").length) AddToolTip( $(".PictoPlan.On"), 'View on the floor plan');
			
			if($(".NomDeStand .LeCommentaire").length) AddToolTip( $(".NomDeStand .LeCommentaire"), 'Add / modify a comment');
		
			if($(".Prior1.AddPrior.Off").length) AddToolTip( $('.Prior1.AddPrior.Off') , "Add to my <b>e-Plan</b><br><b>Normale</b>");
			if($(".Prior1.AddPrior.On").length) AddToolTip( $('.Prior1.AddPrior.On') , "Remove from my <b>e-Plan</b>");
			
			if($(".Prior2.AddPrior.Off").length) AddToolTip( $('.Prior2.AddPrior.Off') , "Add to my <b>e-Plan</b><br><b>High</b> priority");
			if($(".Prior2.AddPrior.On").length) AddToolTip( $('.Prior2.AddPrior.On') , "Remove from my <b>e-Plan</b>");
			
			if($(".LiPicto.New.On").length) AddToolTip( $(".LiPicto.New.On"), 'New exhibitors');
			if($(".LiPicto.Archi.On").length) AddToolTip( $(".LiPicto.Archi.On"), 'Special ARCHI.DESIGNER');
			if($(".LiPicto.Musees.On").length) AddToolTip( $(".LiPicto.Musees.On"), 'Museum itinerary');
			if($(".LiPicto.Publi.On").length) AddToolTip( $(".LiPicto.Publi.On"), 'Publi shopping');
		
		} else {
			
			if($(".PictoWeb.On").length) AddToolTip( $(".PictoWeb.On"), 'Voir le site Web');
			if($(".PictoPlan.On").length) AddToolTip( $(".PictoPlan.On"), 'Voir sur le plan');
			
			if($(".NomDeStand .LeCommentaire").length) AddToolTip( $(".NomDeStand .LeCommentaire"), 'Ajouter / modifier un commentaire');
		
			if($(".Prior1.AddPrior.Off").length) AddToolTip( $('.Prior1.AddPrior.Off') , "Ajouter à mon <b>e-Plan</b><br>Priorité <b>normale</b>");
			if($(".Prior1.AddPrior.On").length) AddToolTip( $('.Prior1.AddPrior.On') , "Retirer de mon <b>e-Plan</b>");
			
			if($(".Prior2.AddPrior.Off").length) AddToolTip( $('.Prior2.AddPrior.Off') , "Ajouter à mon <b>e-Plan</b><br>Priorité <b>haute</b>");
			if($(".Prior2.AddPrior.On").length) AddToolTip( $('.Prior2.AddPrior.On') , "Retirer de mon <b>e-Plan</b>");
			
			if($(".LiPicto.New.On").length) AddToolTip( $(".LiPicto.New.On"), 'Nouveaux exposants');
			if($(".LiPicto.Archi.On").length) AddToolTip( $(".LiPicto.Archi.On"), 'Spécial ARCHI.DESIGNER');
			if($(".LiPicto.Musees.On").length) AddToolTip( $(".LiPicto.Musees.On"), 'Parcours musées');
			if($(".LiPicto.Publi.On").length) AddToolTip( $(".LiPicto.Publi.On"), 'Publi shopping');
			
		}
		
	}
	
function DestroyAllToolTip(){
	
	$('.qtip').each(function() {
							  $(this).qtip("destroy");
							  });
		
	}
	
function MajHeader(){
	

		if($("#DecompteHall").length){
			$.ajax({
					url: "./layouts/ajax/MajHeader.php",
					type: "POST",
					success: function(feedback){
									$('#DecompteHall').html(feedback);
							 }
			});
		}
		
		
		if($(".DecompteEPlan").length){
			$.ajax({
					url: "./layouts/ajax/MajDecompteEplan.php",
					type: "POST",
					success: function(feedback){
									$('.DecompteEPlan').html(feedback);
							 }
			});
		}
		
	}
	
	
function CallBackInsertionNyro(){
	
	//AddPrior();
	
	$(".PictoWeb.On").click(function(){
				window.open('http://' + $(this).attr('LinkWeb'), '', 'menubar=yes, status=yes, scrollbars=yes, menubar=yes, width=800, height=600, resizable=yes');
	});
	
	GenereAllToolTip();
	
}

function GetInsertionFromFlash(aNumeroInsertion){
				 $.nyroModalManual({
												  url: './layouts/ajax/InsertionView.php?aNumeroInsertion=' + aNumeroInsertion,
												  endShowContent: CallBackInsertionNyro,
													width: 605,
													height:620
												});
	
}

function LoadPresc(IdPresc){
		
		$.ajax({
					url: "./layouts/ajax/InsertionAnnuaireInfos.php",
					type: "POST",
					data: {ProdId:IdPresc},
					success: function(feedback){
									$('.PhotoAnnuaire').html(feedback);
							 }
			});
	}


function maxlength(maxlength) {
	
	if($('body').hasClass('Eng')) MaxMsg = 'character maximum';
	else MaxMsg = ' caractères maximum';
	
	var lgTxt = new String($('#ComTextArea').val());
	
	if(lgTxt.length>maxlength) {
		$('#ComTextArea').val($('#ComTextArea').val().substr(0,maxlength));
		alert(maxlength + MaxMsg);
	}
} 